package com.excilys.ymca.util;

import org.apache.http.cookie.Cookie;
import org.apache.http.impl.cookie.BasicClientCookie;

import com.google.inject.Singleton;

@Singleton
public class SessionCookieHolder {

    private Cookie sessionCookie;

    public Cookie getSessionCookie() {
        return cloneCookie(sessionCookie);
    }

    public void setSessionCookie(Cookie sessionCookie) {
        this.sessionCookie = cloneCookie(sessionCookie);
    }

    private static Cookie cloneCookie(Cookie cookie) {
        try {
            return (Cookie) ((BasicClientCookie) cookie).clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }

}
